drop if year>2008
gen post=1 if inlist(year,2005,2006,2007,2008)
replace post=1 if year==2004 & inlist(quarter,3,4)
replace post=1 if year==2004 & inlist(quarter,1,2) & inlist(state,"09","10","11","23","24","33","34","36","42")
replace post=1 if year==2004 & inlist(quarter,1,2) & inlist(state,"44","50")
replace post=1 if year==2003 & inlist(quarter,3,4) & inlist(state,"09","10","11","23","24","33","34","36","42")
replace post=1 if year==2003 & inlist(quarter,3,4) & inlist(state,"44","50")
gen east=1 if inlist(state,"01","09","10","11","17","18","19","21","34")
replace east=1 if inlist(state,"23","24","25","26","27","33","36","37","38")
replace east=1 if inlist(state,"39","42","44","45","47","50","51","54","55")
replace east=0 if east==.
replace post=0 if post==.
tostring naics3,replace
merge m:m naics3 using ind3_table1
keep if _m==3
drop _m

tostring east,gen(eaststr)
gen eastind=eaststr+naics3
drop if state=="29"
gen postxeast=post*east
gen postxint=post*en_int
gen intxeast=en_int*east
gen postxeastxint=post*east*en_int


gen highint=0
replace highint=1 if en_int>.03
gen postxhigh=post*highint
gen eastxhigh=east*highint
gen postxeastxhigh=post*east*highint


gen fulltemp=1 if year==2000 & quarter==2
egen statetemp=max(fulltemp),by(state)
keep if statetemp==1



tostring year quarter,replace
gen yqtr=year+"Q"+quarter
gen ind_qtr=naics3+yqtr
gen state_qtr=state+yqtr
gen state_ind=state+"_"+naics3 
*qui tab ind_qtr,gen(indqtrdum)
encode ind_qtr, gen(ind_qtrf)
qui tab state_ind,gen(STinddum)
qui tab yqtr,gen(qtrdum)
qui tab state,gen(statedum)

gen tempend=emp if year=="2000" & quarter=="2"
egen emp_weight=max(tempend),by(state_ind)
gen temp=emps if year=="2004" & quarter=="2"
egen emp_base=max(temp),by(state_ind)

so yqtr
encode yqtr, gen(trend)

foreach z of varlist statedum1-statedum40 {
gen trend`z'=`z'*trend
drop `z'
}

foreach x of varlist qtrdum1-qtrdum44 {
gen eastxhighx`x' = eastxhigh*`x'
gen intxeastx`x' = intxeast*`x'
}

order intxeastx*
tab naics3,gen(ind)

forvalues i = 1(1)21 {
  qui gen eindtrend`i' = ind`i'*east*trend
 }
forvalues i = 1(1)21 {
  qui gen windtrend`i' = ind`i'*((east-1)^2)*trend
 }

drop if inlist(semps,-1,-2)
drop if inlist(shiras,-1,-2)
drop if inlist(seps,-1,-2)
drop if inlist(sfrmjbgns,-1,-2)
drop if inlist(sfrmjblss,-1,-2) 

so state naics3 yqtr
merge 1:1 state naics3 yqtr using allemp_mergeprep_table1
drop _m
drop if year=="2008" & quarter=="4"
